package com.avecsys.quotemanager.utils;

import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;

/**
 * 
 * @author Sam Sundar K
 * 
 */
public class UIComponentUtils {

	/**
	 * Method to return a boolean value true if the component is null and
	 * component value is null or empty
	 * 
	 * @param component
	 * @return boolean
	 */
	public static boolean isEmpty(UIComponent component) {
		boolean isEmpty = false;
		if (component == null) {
			isEmpty = true;
		} else {
			if (component instanceof UIInput) {
				UIInput uiInput = (UIInput) component;
				if (uiInput.getSubmittedValue() != null
						&& uiInput.getSubmittedValue().toString().trim()
								.length() == 0) {
					isEmpty = true;
				}
			} else {
				new Exception(
						"UIComponentUtils.isEmpty Component Case Not Handled");
			}
		}
		return isEmpty;
	}
}
